<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
	function sosuo() {
		var lpath = location.pathname;
		$("#soform").attr("action", lpath + "?pageNo=" + 1);

		$("#soform").submit();
	}
</script>
</head>

<body>
	<div class="panel panel-info panel-content">
		<div class="panel-heading">
			<button style="float: right" type="button" onclick="addDelivery()" class="btn btn-info">
				<span class="glyphicon glyphicon-plus"></span>
				&nbsp;新增物流信息
			</button>
			<form id="soform" method="post">
				<table>
					<tr>
						<td class="w80" style="padding-top: 5px">
							<label for="companyname" class="center-block">物流公司名称：</label>
						</td>
						<td class="w150 ">
							<input type="text" class="form-control" name="so_companyname" value="${so_companyname!}" id="so_companyname" placeholder="物流公司名称" data-options="">
						</td>
	
						<td style="padding-left: 10px">
							<div class="input-group">
								<span class="input-group-btn">
									<button class="btn btn-default" type="button" onclick="sosuo()">搜索</button>
								</span>
							</div>
						</td>
					</tr>
				</table>
			</form>
		</div>
		<table class="table table-hover table-bordered table-striped table-condensed">
			<thead>
				<tr>
					<th width="5">#</th>
					<th width="20%">物流公司名称</th>
					<th width="20%">物流公司代码</th>
					<th width="20%">是否支持api</th>
					<th width="20%">排序</th>
					<th width="15%">操作</th>
				</tr>
			</thead>
			[#list pagination.list as delivery ]
			<tr>
				<td align="center">${delivery_index + 1}</td>
				<td align="center">${delivery.companyName!}</td>
				<td align="center">${delivery.companyCode!}</td>
				<td align="center">[#if delivery.ifSupportApi==1]是
									[#elseif delivery.ifSupportApi==0]否
									[/#if]
				</td>
				<td align="center">${delivery.seq!}</td>
				<td align="center">
					<button type="button" class="btn btn-danger btn-xs delbtn" onclick="edit('${delivery.id}','${delivery.companyName!}','${delivery.companyCode!}','${delivery.ifSupportApi!}','${delivery.seq!}')">编辑</button>
					<button type="button" class="btn btn-danger btn-xs delbtn" onclick="del('${delivery.id}')">删除</button>
				</td>
			</tr>
			[/#list]
		</table>

		<div class="panel-footer">[@fenye p = pagination form = 'infoForm' /]</div>
	</div>


	<!-- 新增的弹出页 -->
	<div id="addDelivery" style="width:450px; height:250px; display: none;">
		<form id="addform" method="post" class="form-horizontal" role="form">

			<div class="form-group">
				<label class="col-sm-3 control-label" id="clickforpro">物流公司名称</label>
				<div class="col-sm-7">
					<input type="text" class="form-control" placeholder="请输入物流公司名称" min="1" required="required" name="companyName" id="addname">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">物流公司代码</label>
				<div class="col-sm-7">
					<input type="text" class="form-control" placeholder="请输入消息代码" min="1" required="required" name="companyCode" id="addcode">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">是否支持api</label>
				<div class="col-sm-7">
					<select class="form-control" name="ifSupportApi" id="addIfApi">
						<option value="1">是</option>
						<option value="0">否</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">排序</label>
				<div class="col-sm-7">
					<input type="text" class="form-control" placeholder="" min="1" required="required" name="seq" id="addseq">
				</div>
			</div>
			<div class="form-group" style="margin-top: 15px;">
				<div class="col-sm-offset-3 col-sm-10">
					<input id="addsubmit" onclick="subadd()" type="button" class="btn btn-default" value="提交" />
				</div>
			</div>
		</form>
	</div>

	<!-- 编辑的弹出页 -->
	<div id="editDelivery" style="width:450px; height:250px; display: none;">
		<form id="editform" method="post" class="form-horizontal" role="form">
			<input type="hidden" name="id" id="editid">
			<div class="form-group">
				<label class="col-sm-3 control-label" id="clickforpro">物流公司名称</label>
				<div class="col-sm-7">
					<input type="text" class="form-control" placeholder="请输入物流公司名称" min="1" required="required" name="companyName" id="editname">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">物流公司代码</label>
				<div class="col-sm-7">
					<input type="text" class="form-control" placeholder="请输入消息代码" min="1" required="required" name="companyCode" id="editcode">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">是否支持api</label>
				<div class="col-sm-7">
					<select class="form-control" name="ifSupportApi" id="editIfApi">
						<option value="1">是</option>
						<option value="0">否</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">排序</label>
				<div class="col-sm-7">
					<input type="text" class="form-control" placeholder="" min="1" required="required" name="seq" id="editseq">
				</div>
			</div>
			<div class="form-group" style="margin-top: 15px;">
				<div class="col-sm-offset-3 col-sm-10">
					<input id="addsubmit" type="button" onclick="subedit()" class="btn btn-default" value="提交" />
				</div>
			</div>
		</form>
	</div>
</body>
</html>
<script type="text/javascript">
	//展示新增窗口
	function addDelivery() {
		dialog = art.dialog({
			title : "新增物流信息",
			lock : true,
			content : document.getElementById('addDelivery')
		});
	}
	//删除
	function del(id) {//弹出警告框判断是否删除
		if (confirm('是否确认删除')) {
			$.ajax({
				url : '/delivery/ajax_del.do',
				type : 'get',
				dataType : 'json',
				data : {
					id : id
				},
				beforeSend : function() {
					art.dialog.tips("删除中...");
				},
				success : function(data) {
					if (data.success) {
						location.reload();
					} else {
						error_msg(data.msg, function() {
							location.reload();
						});
					}
				}
			});
		}
	}
	//打开编辑窗口
	function edit(id, name, code, ifApi, seq) {
		$("#editid").val(id);
		$("#editname").val(name);
		$("#editcode").val(code);
		$("#editIfApi").val(ifApi);
		$("#editseq").val(seq);

		dialog = art.dialog({
			title : "修改物流信息",
			lock : true,
			content : document.getElementById('editDelivery')
		});
	}
	//新增提交
	function subadd(){
	[#--提交之前 form 要手动进行验证--]
	
	var name = $("input[id='addname']").val();
	if (!name) {
		alert('物流公司名称必须填写!');
		return;
	}
	var code = $("input[id='addcode']").val();
	if (!code) {
		alert('物流公司代码必须填写!');
		return;
	}
	var ifApi = $("select[id='addIfApi']").val();
	if (!ifApi) {
		alert('请选择是否支持api!');
		return;
	}
	var seq = $("input[id='addseq']").val();
	if (!seq) {
		alert('请输入排序!');
		return;
	}
	art.dialog.post({
		url: "/delivery/ajax_save.do",
        data:$("#addform").serialize(),
        success: function(data){
            if(data.success){
                location.reload();
            }else{
            	alert(data.msg)
            }
        }
	},"加载中...");
	
	}
	
	//编辑提交
	function subedit(){
	[#--提交之前 form 要手动进行验证--]
	
	var name = $("input[id='editname']").val();
	if (!name) {
		alert('物流公司名称必须填写!');
		return;
	}
	var code = $("input[id='editcode']").val();
	if (!code) {
		alert('物流公司代码必须填写!');
		return;
	}
	var ifApi = $("select[id='editIfApi']").val();
	if (!ifApi) {
		alert('请选择是否支持api!');
		return;
	}
	var seq = $("input[id='editseq']").val();
	if (!seq) {
		alert('请输入排序!');
		return;
	}
	art.dialog.post({
		url: "/delivery/ajax_save.do",
        data:$("#editform").serialize(),
        success: function(data){
            if(data.success){
                location.reload();
            }else{
            	alert(data.msg)
            }
        }
	},"加载中...");
	}
	
	

</script>